package com.tfswue.yhj.service;

import com.tfswue.yhj.event.UserRegisteredEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Service;

@Service
public class EventPublisherService implements ApplicationEventPublisherAware {
    private ApplicationEventPublisher publisher;  // 添加成员变量声明

    @Override
    public void setApplicationEventPublisher(
            ApplicationEventPublisher applicationEventPublisher) {
        this.publisher = applicationEventPublisher;
    }

    //发布自定义事件
    public void publishUserRegistered(String username, String email) {
        publisher.publishEvent(new UserRegisteredEvent(this, username, email));
    }
}
